﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using YFurion.Entities;
using YFurion.Utils;

namespace UpperComputer.Core.Entities
{
    public class BaseMenu : FullEntity, IEntityTypeBuilder<BaseMenu>, IEntitySeedData<BaseMenu>
    {
        public BaseMenu()
        {
            BaseMenuButton = new HashSet<BaseMenuButton>();
        }
        public string Code { get; set; }

        public string DisplayName { get; set; }

        public string ParentCode { get; set; }

        public string Link { get; set; }

        public int Sort { get; set; }

        public string Icon { get; set; }

        public bool IsActive { get; set; }

        public string Description { get; set; }

        public virtual ICollection<BaseMenuButton> BaseMenuButton { get; set; }

        public void Configure(EntityTypeBuilder<BaseMenu> entity, DbContext dbContext, Type dbContextLocator)
        {
            entity.HasIndex(e => e.Code, "UQ__BaseMenu")
                    .IsUnique();

            entity.Property(e => e.Id)
                 .ValueGeneratedNever();

            entity.Property(e => e.Code)
                .IsRequired()
                .HasMaxLength(50)
                .IsUnicode(false);

            entity.Property(e => e.Description).HasMaxLength(255);

            entity.Property(e => e.DisplayName)
                .IsRequired()
                .HasMaxLength(50);

            entity.Property(e => e.Icon).HasMaxLength(100);

            entity.Property(e => e.Link).HasMaxLength(200);

            entity.Property(e => e.ParentCode)
                .HasMaxLength(50)
                .IsUnicode(false);
        }

        public IEnumerable<BaseMenu> HasData(DbContext dbContext, Type dbContextLocator)
        {
            return new List<BaseMenu>
            {
                #region 用户权限
                new BaseMenu
                {
                    Id = YIDGenerator.NextId(),
                    Code = "Permissions",
                    ParentCode = "",
                    DisplayName = "用户权限",
                    Icon = "TeamOutlined",
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    IsActive = true,
                    Sort = 1,
                    Description = "用户权限"
                },
                new BaseMenu
                {
                    Id = YIDGenerator.NextId(),
                    Code = "Menu",
                    ParentCode = "Permissions",
                    DisplayName = "菜单管理",
                    Icon = "TableOutlined",
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    IsActive = true,
                    Sort = 1,
                    Description = "菜单管理"
                },
                new BaseMenu
                {
                    Id = YIDGenerator.NextId(),
                    Code = "MenuButton",
                    ParentCode = "Permissions",
                    DisplayName = "按钮管理",
                    Icon = "YoutubeOutlined",
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    IsActive = true,
                    Sort = 2,
                    Description = "按钮管理"
                },
                new BaseMenu
                {
                    Id = YIDGenerator.NextId(),
                    Code = "Role",
                    ParentCode = "Permissions",
                    DisplayName = "角色管理",
                    Icon = "UserSwitchOutlined",
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    IsActive = true,
                    Sort = 3,
                    Description = "角色管理"
                },
                new BaseMenu
                {
                    Id = YIDGenerator.NextId(),
                    Code = "User",
                    ParentCode = "Permissions",
                    DisplayName = "用户管理",
                    Icon = "UserOutlined",
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    IsActive = true,
                    Sort = 4,
                    Description = "用户管理"
                },
                #endregion

                #region 系统日志
                new BaseMenu
                {
                    Id = YIDGenerator.NextId(),
                    Code = "SystemLog",
                    ParentCode = "",
                    DisplayName = "系统日志",
                    Icon = "DesktopOutlined",
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    IsActive = true,
                    Sort = 2,
                    Description = "系统日志"
                },
                new BaseMenu
                {
                    Id = YIDGenerator.NextId(),
                    Code = "LoginInOrOutLog",
                    ParentCode = "SystemLog",
                    DisplayName = "用户日志",
                    Icon = "CalendarOutlined",
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    IsActive = true,
                    Sort = 1,
                    Description = "用户日志"
                },
                new BaseMenu
                {
                    Id = YIDGenerator.NextId(),
                    Code = "AuditLog",
                    ParentCode = "SystemLog",
                    DisplayName = "审计日志",
                    Icon = "DesktopOutlined",
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    IsActive = true,
                    Sort = 2,
                    Description = "操作日志"
                }
                #endregion
            };
        }
    }
}